import { Controller } from "../../mvc/core/Controller";
import { DataEvent } from "../events/DataEvent";
import { OperateGodSoulVo } from "../view/godSoul/vo/OperateGodSoulVo";
import { GameProxy } from "../mvc/GameProxy";
import { SQiXingShenHunInfo } from "../../../Message/Public/SQiXingShenHunInfo";
import { IGodSoulModule } from "../../../modules/interfaces/IGodSoulModule";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SAttribute } from "../../../Message/Public/SAttribute";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { SystemSetter } from "../view/system/SystemSetter";
import { Alert } from "../../../com/mui/controls/Alert";
import { Language } from "../../../extend/language/Language";
import { WindowEvent } from "../../component/window/WindowEvent";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { ServerCommand } from "../mvc/ServerCommand";
import { IView } from "../../mvc/interfaces/IView";
import { GodSoulModule } from "../../../modules/GodSoulModule";
type int = number;
//class GodSoulController
    
    export  class GodSoulController extends Controller
    {
       

        /* internal  */onGodSoulPromoteHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as OperateGodSoulVo;
            GameProxy.roleProxy.operateQixingShenhun(loc1);
            return;
        }

        /* internal  */onSetStarDataHandler(arg1: DataEvent): void
        {
            var loc1=null;
            loc1 = arg1.data as SQiXingShenHunInfo;
            cache.godSoul.openInfo = loc1.openInfo;
            cache.godSoul.levelInfo = loc1.levelInfo;
            cache.godSoul.expInfo = loc1.expInfo;
            IGodSoulModule(view).setStarData();
            return;
        }

        /* internal  */onQixingShenhunGoldTimes(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SAttribute;
            cache.godSoul.useTime = loc1.value;
            IGodSoulModule(view).setStarData();
            return;
        }

        /* internal  */onPackChangeHandler(arg1: Object=null): void
        {
            IGodSoulModule(view).packChange();
            return;
        }

        /* internal  */onUpgradeSuccessHandler(arg1: DataEvent): void
        {
            IGodSoulModule(view).showUpgradeEffectPlayer();
            return;
        }

        /* internal  */onIntensifySuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data;
            IGodSoulModule(view).setplayCriEffect(loc1.exp, loc1.isCrit);
            return;
        }

        /* internal  */onShowGuideHandler(arg1): void
        {
            var e;
            var onClickHandler: Function;

            var loc1;
            onClickHandler = null;
            e = arg1;
            onClickHandler = (arg1: int): void
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideActiveByEvent, {"mainId": 7, "stepId": 1}));
                return;
            }
            if (cache.clientSettingCache.isGodSoulGuild && cache.role.entityInfo.level >= 75) 
            {
                cache.clientSettingCache.isGodSoulGuild = false;
                SystemSetter.systemGuideSetterInfo.setSystemInfo("isGodSoulGuild", false);
                Dispatcher.dispatchEvent(new DataEvent(EventName.SaveGuideSystemSetter));
                Alert.show(Language.getString(28692), null, Alert.OK, null, onClickHandler);
            }
            return;
        }

        /* internal  */onGetStarDataHandler(arg1: DataEvent): void
        {
            GameProxy.roleProxy.getQixingShenhunView();
            return;
        }

        /* internal  */showModule(arg1: WindowEvent): void
        {
            cache.godSoul.needShowOpenTip = true;
            Dispatcher.addEventListener(EventName.GodSoulIntensifySuccess, this.onIntensifySuccessHandler);
            Dispatcher.addEventListener(EventName.GodSoulSetStarData, this.onSetStarDataHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateQixingShenhunGoldTimes, this.onQixingShenhunGoldTimes);
            NetDispatcher.addCmdListener(ServerCommand.BackpackDataChange, this.onPackChangeHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onPackChangeHandler);
            return;
        }

        /* internal  */closeModule(arg1: WindowEvent): void
        {
            cache.godSoul.needShowOpenTip = false;
            Dispatcher.removeEventListener(EventName.GodSoulIntensifySuccess, this.onIntensifySuccessHandler);
            Dispatcher.removeEventListener(EventName.GodSoulSetStarData, this.onSetStarDataHandler);
            NetDispatcher.removeCmdListener(EGateCommand._ECmdGateQixingShenhunGoldTimes, this.onQixingShenhunGoldTimes);
            NetDispatcher.removeCmdListener(ServerCommand.BackpackDataChange, this.onPackChangeHandler);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.onPackChangeHandler);
            return;
        }

        protected /* override */ initView(): IView
        {
            if (this._module == null) 
            {
                this._module = new GodSoulModule();
                this._module.addEventListener(WindowEvent.SHOW, this.showModule);
                this._module.addEventListener(WindowEvent.CLOSE, this.closeModule);
            }
            return this._module;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.GodSoulOper, this.onGodSoulPromoteHandler);
            Dispatcher.addEventListener(EventName.GodSoulGetStarData, this.onGetStarDataHandler);
            Dispatcher.addEventListener(EventName.GodSoulUpgradeSuccess, this.onUpgradeSuccessHandler);
            Dispatcher.addEventListener(EventName.Scene_Update, this.onShowGuideHandler);
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.onShowGuideHandler);
            return;
        }

        private /* var */_module: IGodSoulModule;
    }
